<div class="layuimini-main">

    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">网站名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value="${obj.title}" class="layui-input">
                <tip>填写网站名称。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网站地址</label>
            <div class="layui-input-block">
                <input type="text" name="link" lay-verify="required" placeholder="请输入地址" value="${obj.link}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">用户名</label>
            <div class="layui-input-block">
                <input type="text" name="username" autocomplete="off" lay-verify="required" placeholder="请输入用户名" value="${obj.username}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" autocomplete="off" lay-verify="required" placeholder="请输入密码" value="${obj.password}" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="description" class="layui-textarea" placeholder="请输入备注信息">${obj.description}</textarea>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="saveBtn">确认保存</button>

            </div>
        </div>
    </div>
</div>
<% include("/public/ajax.html"){} %>
<script>
    layui.use(['form', 'table'], function () {
        var form = layui.form,
                layer = layui.layer,
                table = layui.table,
                $ = layui.$;

        /**
         * 初始化表单，要加上，不然刷新部分组件可能会不加载
         */
        form.render();

        // 当前弹出层，防止ID被覆盖
        var parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData = data.field;
            postData.id='${obj.id}';
            $.ajax({
                url: '/site/ajax/edit',
                type: 'POST',
                dataType: 'json',
                contentType: "application/json",
                data: JSON.stringify(postData),
                success: function (result) {
                    var index = layer.msg(result.msg);
                    if(result.code == 0) {
                        layer.close(index);
                        layer.close(parentIndex);
                        return false;
                    }

                },
                error:function(err){
                    layer.alert(err.responseJSON.msg, {icon: 5});
                }

            });

            return false;
        });

    });


</script>